package cn.pku.sirx.snad.ass.strategy.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;

import cn.pku.sirx.snad.ad.dao.IAdContentDao;
import cn.pku.sirx.snad.ad.model.UserContext;
import cn.pku.sirx.snad.ad.model.WeightedKeyword;
import cn.pku.sirx.snad.ad.model.entity.AdContent;
import cn.pku.sirx.snad.ass.strategy.IAdRetrievalStrategy;

/**
 * @author WangXiao
 */
public class AdRetrievalStrategyImpl implements IAdRetrievalStrategy {

	@Override
	public List<AdContent> retrieveAds(UserContext userContext) {
		Assert.notNull(userContext);
		
		Set<AdContent> adContentSet = new HashSet<AdContent>();
		/*
		 * retrieve by keywords
		 */
		LOG.info("Retrieve by keywords");
		List<WeightedKeyword> keywords = userContext.getWeightedKeywords();
		List<String> keywordStrings = new ArrayList<String>(keywords.size());
		for (WeightedKeyword weightedKeyword : keywords) {
			keywordStrings.add(weightedKeyword.getKeyWord());
		}
		adContentSet.addAll(adContentDao.getByKeywords(keywordStrings));
		/*
		 * retrieve by influences
		 */
		LOG.info("Retrieve by influences");
//		List<AdContent> result = adContentDao.getByKeywords(keywords);
		
		return null;
	}
	
	private IAdContentDao adContentDao;
	
	private static final Log LOG = LogFactory.getLog(AdRetrievalStrategyImpl.class);

	public void setAdContentDao(IAdContentDao adContentDao) {
		this.adContentDao = adContentDao;
	}

}
